package cn.schoolwow.workflow.module.task.action.flow.common;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.entity.WorkFlowTask;

public class CheckWorkFlowTaskExistFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DAO dao = flowContext.checkInstanceData(DAO.class);
        long taskId = flowContext.checkData("taskId", long.class);

        WorkFlowTask workFlowTask = dao.query(WorkFlowTask.class)
                .addQuery("id", taskId)
                .execute()
                .getOne();
        if(null==workFlowTask){
            throw new IllegalArgumentException("工作流任务不存在!id:"+taskId);
        }
        flowContext.putTemporaryInstanceData(workFlowTask);
    }

    @Override
    public String name() {
        return "检查工作流任务是否存在";
    }
}
